#ifndef __IOFILE_H__
#define __IOFILE_H__

#include "Config.h"
#include "include/IIOFile.h"

class CFileSystem;
class CIOFile;
typedef IListContainer<CIOFile>	FileListType;
#ifdef __COMPILE_WIN32__
    #define DIR_SEPARATOR_STR       "\\"
    #define DIR_SEPARATOR_CHAR      '\\'
#endif

#ifdef __COMPILE_LINUX__
    #define DIR_SEPARATOR_STR       "/"
    #define DIR_SEPARATOR_CHAR      '/'
    #include <dirent.h>
#endif

class CIOFile : public IIOFile
{
protected:
	FileListType FileList;
	u8 *Buffer;
	s32 SearchingID;
	CFileSystem *fs;
#ifdef __COMPILE_LINUX__
    DIR *Dir;
#endif

public:
	CIOFile(stringc dir,stringc filename,CFileSystem *fsp);
	virtual ~CIOFile();

	bool IsDirectoryString(stringc Dir);
	stringc ConvertToDir(stringc Dir);
	void CreateChildTree();
	void AddChild(CIOFile *newChild);

	virtual u32 CopyFromFileToMemory(u32 Size)			= 0;
	virtual IIOFile *CreateBinaryFile(stringc Name)		= 0;
	virtual bool OpenFileForWriting(stringc Name)		= 0;

	CIOFile *Search(stringc Name);
	virtual u8 *GetBuffer()		{	return Buffer;	}
	bool LoadEntireFile();

	IIOFile *GetFileByIndex(u32 Index);
	u32 GetNumElements();

	virtual u32 WriteBinary(void *Buffer,u32 Size)				= 0;
	virtual bool CloseFile()									= 0;

	virtual bool FindFirst(stringc Path,FindDataStrc *fdata)	= 0;
	virtual bool FindNext(FindDataStrc *fdata)					= 0;
	virtual bool FindClose()									= 0;
	virtual bool IsSubDir(FindDataStrc *fdata)					= 0;
};

#endif
